package com.cvte.sunkit.utils

import android.app.Activity

object ActivityCollector {
    private val activities = ArrayList<Activity>()

    /**
     * onCreate调用
     */
    fun addActivity(activity: Activity) {
        activities.add(activity)
    }

    /**
     * onDestroy中调用
     */
    fun removeActivity(activity: Activity) {
        activities.remove(activity)
    }

    /**
     * 要退出程序，直接调用这个方法*/
    fun finishAll() {
        activities.forEach {
            if (!it.isFinishing) it.finish()
        }
        activities.clear()
    }

}